package com.yst.web.utils;

import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Objects;

public class ReflectUtils {
    public static void scanAllClass(String...excludePackages){
        StackTraceElement[] stackTraceElements=  Thread.currentThread().getStackTrace();
        Arrays.asList(stackTraceElements)
                .forEach((e)->{
                    try {
                        Class<?> clazz=Class.forName(e.getClassName());
                        if (Objects.nonNull(clazz.getPackage())) {
                            System.out.println(clazz.getPackage().getName());
                            if (Objects.nonNull(clazz.getPackage().getName())&&Objects.nonNull(clazz.getClassLoader())) {
                               Enumeration<URL> urls=Thread.currentThread().getContextClassLoader().getResources(clazz.getPackage().getName());
                               while(urls.hasMoreElements()){
                                   URL url=urls.nextElement();
                                   System.out.println("url:"+url.toString());
                               }
                            }
                        }
                    } catch (ClassNotFoundException ex) {
                        throw new RuntimeException(ex);
                    } catch (IOException ex) {
                        throw new RuntimeException(ex);
                    }
                });
    }

    public static void main(String[] args) {
        scanAllClass();
    }
}
